package sseGameApps.controller.mdkbr.main;

import java.util.Date;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import sseGameApps.model.mdkbr.MdDecoration;
import sseGameApps.service.mdkbr.MdDecorationService;

public class MdSchoolTrnmntResultController extends Controller {

    private MdDecorationService serviceMdDecoration = new MdDecorationService();

    @Override
    public Navigation run() throws Exception {

        Date sysDate = new Date(System.currentTimeMillis());

        MdDecoration mdDecoration = serviceMdDecoration.getMdDecoration(asString("userId"));

        if (mdDecoration == null){
            mdDecoration = serviceMdDecoration.setDefaultMdDecoration(asString("userId"));
        }

        if("P-WIN".equals(asString("battleResult"))){
            if ("1".equals(asString("fieldType"))) {
                mdDecoration.setEventCompDate1(sysDate);
                mdDecoration.setEventComplete1(true);
            } else if ("2".equals(asString("fieldType"))) {
                mdDecoration.setEventCompDate2(sysDate);
                mdDecoration.setEventComplete2(true);
            } else if ("3".equals(asString("fieldType"))) {
                mdDecoration.setEventCompDate3(sysDate);
                mdDecoration.setEventComplete3(true);
            }
            serviceMdDecoration.putMdDecoration(mdDecoration);
        }

        return null;
    }
}
